package com.lucifer.cloud.boot.blog.chat.api;
import com.lucifer.cloud.boot.blog.chat.common.RestResult;
import com.lucifer.cloud.boot.blog.chat.service.DocService;
import com.lucifer.cloud.boot.blog.chat.service.response.DocVO;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/chat/api/doc")
@RequiredArgsConstructor
public class DocAPI {

    private final DocService docService;

    @GetMapping("/list")
    public RestResult<List<DocVO>> list() {
        return RestResult.buildSuccessResult(docService.list());
    }

    @GetMapping("/load")
    public RestResult<String> load() {
        docService.loadData();
        return RestResult.buildSuccessResult();
    }

    @PostMapping("/upload")
    public RestResult upload(@RequestParam("file")MultipartFile file) {
        return RestResult.buildSuccessResult(docService.saveFile(file));
    }



}
